package org.example.design.template;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @Classname NetMall
 * @Description 基础商品推广服务，生成电商推广海报，里面包含个人的邀请码
 * @Date 2020/11/12 9:45 上午
 * @Created by xiangjd
 */
public abstract class NetMall {

    protected Logger logger = LoggerFactory.getLogger(NetMall.class);

    //用户id
    private String uid;
    //用户密码
    private String pwd;

    public NetMall(String uid, String pwd) {
        this.uid = uid;
        this.pwd = pwd;
    }

    /**
     * 生成商品推广海报
     *
     * @param skuUrl 商品地址(京东、淘宝、当当)
     * @return 海报图片base64位信息
     */
    public String generateGoodsPoster(String skuUrl) {
        //验证登陆
        if (!login(uid, pwd)) {
            return null;
        }
        //爬取商品
        Map<String, String> reptile = reptile(skuUrl);
        //组装海报
        return createBase64(reptile);

    }

    //模拟登陆
    protected abstract Boolean login(String uid, String pwd);

    //通过爬虫爬取登陆后优惠的商品价格
    protected abstract Map<String, String> reptile(String skuUrl);

    //生成商品海报
    protected abstract String createBase64(Map<String, String> goodsInfo);
}
